package com.privatework.backedserver.controller.leave;

import com.privatework.common.requestvo.leave.LeaveInfoReqVo;
import com.privatework.common.service.leave.LeaveService;
import com.privatework.common.utils.PageUtil;
import com.privatework.common.utils.ResultVoUtil;
import com.privatework.common.vo.PageVo;
import com.privatework.common.vo.ResultVo;
import com.privatework.common.vo.leave.LeaveInfoResultVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

/**
 * 用户 Controller
 *
 * @author johnny
 * @create 2020-07-10 下午4:08
 **/
@RestController
@Slf4j
@RequestMapping("/leave")
public class LeaveController {

    @Autowired
    private LeaveService leaveService;


    @GetMapping("/listByCondition")
    public ResultVo listByCondition(LeaveInfoReqVo leaveInfoReqVo, PageVo pageVo) {
        pageVo.setPageNumber(pageVo.getPageNumber() - 1);
        Page<LeaveInfoResultVo> page = leaveService.listByCondition(leaveInfoReqVo, PageUtil.initPage(pageVo));
        return ResultVoUtil.success(page);
    }


    @PostMapping("/submitLeave")
    public ResultVo submitLeave(@RequestBody LeaveInfoReqVo leaveInfoReqVo) {
        log.info("【leaveInfoReqVo ： {}】  ", leaveInfoReqVo);
        leaveService.submitLeave(leaveInfoReqVo);
        return ResultVoUtil.success();
    }

    @PostMapping("/submitaddLeave")
    public ResultVo submitaddLeave(@RequestBody LeaveInfoReqVo leaveInfoReqVo) {
        log.info("【leaveInfoReqVo ： {}】  ", leaveInfoReqVo);
        leaveService.submitaddLeave(leaveInfoReqVo);
        return ResultVoUtil.success();
    }


}